import Vue from 'vue'
import Router from 'vue-router'

import ResourceList from '@/components/resources/publicResourceList'
import SymbolLibrary from '@/components/resources/SymbolLibrary'
import expertiseBase from '@/components/resources/expertiseBase'
import literatureResource from '@/components/resources/literatureResource'
import webLibrary from '@/components/resources/webLibrary'
import moocCurriculum from '@/components/resources/moocCurriculum'
import materialLibrary from '@/components/resources/materialLibrary'
import toolsCenter from '@/components/resources/toolsCenter'
import newPersonalPage from '@/components/user/userPage/newPersonalPage'
import overView from '@/components/user/subPage/overView'
import project from '@/components/user/subPage/project'
import todoList from '@/components/user/subPage/todoList'
import permission from '@/components/user/subPage/permission'
import userInfo from '@/components/user/subPage/userInfo'
import resourceList from '@/components/user/subPage/resourceList'
import classList from '@/components/class/classList'
import projectList from '@/components/project/projectList'
import newMap from '@/components/map/newMap'
import createQuestions from '@/components/questions/createQuestions'
import previewQuestions from '@/components/questions/previewQuestions'
import answerPage from '@/components/questions/answerPage'
import AutomaticPaper from '@/components/questions/AutomaticPaper'
import myQuestionBank from '@/components/user/subPage/myQuestionBank'
import classTests from '@/components/user/subPage/classTests'
import questionBankDetail from '@/components/user/subPage/questionBankDetail'
import questionnaireManagement from '@/components/user/subPage/questionnaireManagement'
import Static from '@/components/questions/Static'
// const originalPush = Router.prototype.push
// Router.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }
Vue.use(Router);

const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};

const routes = [
  {
    path: "/",
    name: "Navigation",
    component: resolve => require(["@/components/navigation"], resolve),
    children: [
      {
        path: "/",
        redirect: "home"
      },
      {
        path: "/home",
        name: "home",
        component: resolve =>
          require(["@/components/home/home"], resolve)
      },
      {
        path: "/permission/:level/:id",
        name: "permission",
        component: resolve =>
          require(["@/components/permissionManager"], resolve)
      },
      {
        path: "/projectList",
        name: "projectList",
        component: projectList,
      },
      {
        path: "/projectInfo/:projectId",
        name: "projectInfo",
        component: resolve =>
          require(["@/components/project/projectDetail"], resolve)
      },
      {
        path: "/newProject",
        name: "newProject",
        component: resolve =>
          require(["@/components/project/newProject"], resolve)
      },
      {
        path: "/classInfo",
        name: "classInfo",
        component: resolve =>
          require(["@/components/class/classDetail"], resolve)
      },
      {
        path: "/newPersonalPage",
        name: "newPersonalPage",
        component: newPersonalPage,
        children: [
          {
            path: "/",
            redirect: "userInfo"
          },
          {
            path: "/newPersonalPage/overView",
            name: "overView",
            component: overView,
          },
          {
            path: "/newPersonalPage/project",
            name: "project",
            component: project
          },
          {
            path: "/newPersonalPage/todoList",
            name: "todoList",
            component: todoList
          },
          {
            path: "/newPersonalPage/permission",
            name: "permission",
            component: permission
          },
          {
            path: "/newPersonalPage/userInfo",
            name: "userInfo",
            component: userInfo
          }
          ,
          {
            path: "/newPersonalPage/resourceList",
            name: "resourceList",
            component: resourceList
          },
          {
            path:"/newPersonalPage/myQuestionBank",
            name: "myQuestionBank",
            component: myQuestionBank
          },
          {
            path:"/newPersonalPage/questionnaireManagement",
            name: "questionnaireManagement",
            component: questionnaireManagement
          },


        ]
      },
      {
        path: "/classList",
        name: "classList",
        component: classList,
      },
      {
        path: "/newClass",
        name: "newClass",
        component: resolve =>
          require(["@/components/class/newClass"], resolve)
      },
      // {
      //   path: "/memberPage/:id",
      //   name: "MemberDetailPage",
      //   component: resolve =>
      //     require(["@/components/user/userPage/memberDetailPage"], resolve)
      // },
      // { path: 'resourceList', name: 'resourceList', component: resolve => (require(["@/components/resources/resourceList"], resolve)) },
      {
        path: "/publicResource",
        name: "PublicResource",
        component: ResourceList,
        children: [
          {
            path: "/",
            redirect: "SymbolLibrary"
          },
          {
            path: 'SymbolLibrary',
            name: 'SymbolLibrary',
            component: SymbolLibrary,
          },
          {
            path: 'expertiseBase',
            name: 'expertiseBase',
            component: expertiseBase,
          },
          {
            path: 'literatureResource',
            name: 'literatureResource',
            component: literatureResource,

          },
          {
            path: 'webLibrary',
            name: 'webLibrary',
            component: webLibrary,

          },
          {
            path: 'moocCurriculum',
            name: 'moocCurriculum',
            component: moocCurriculum,

          },
          {
            path: 'materialLibrary',
            name: 'materialLibrary',
            component: materialLibrary,
          },
          {
            path: 'toolsCenter',
            name: 'toolsCenter',
            component: toolsCenter
          },
        ]
      },
      {
        path: "/login",
        name: "Login",
        component: resolve =>
          require(["@/components/user/userState/login"], resolve)
      },
      {
        path: "/register",
        name: "Register",
        component: resolve =>
          require(["@/components/user/userState/register"], resolve)
      },
      
      // {
      //   path: "resetPassword/:email",
      //   name: "resetPassword",
      //   component: resolve =>
      //     require(["@/components/user/userState/resetPwd"], resolve)
      // },
      // {
      //   path: "resourceCenter",
      //   name: "resourceCenter",
      //   component: resolve =>
      //     require(["@/components/resources/resourceCenter"], resolve)
      // },

    ]
  },
  {
    path: "/map",
    name: "map",
    component: newMap
  },
  {
    path:"/createQuestions",
    name: "createQuestions",
    component: createQuestions
  },
  {
    path:"/previewQuestions",
    name: "previewQuestions",
    component: previewQuestions
  },
  {
    path:"/answerPage",
    name: "answerPage",
    component: answerPage
  },
  {
    path:"/AutomaticPaper",
    name: "AutomaticPaper",
    component: AutomaticPaper
  },
  {
    path:"/classTests",
    name: "classTests",
    component: classTests
  },
  {
    path:"/questionBankDetail",
    name: "questionBankDetail",
    component: questionBankDetail
  },
  {
    path:"/Static",
    name: "Static",
    component: Static
  },


];


export default new Router({
  routes,
  mode: "history",
  base: '/visualCoursePlatform', //打包项目的根目录
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { x: 0, y: 0 };
    }
  }
});